var pomelo = require('pomelo');
var utils = require('../util/utils');
var actorDao = module.exports;
actorDao.getAllSkillValue = function(cb){
    var sql = 'select a.*,b.*,c.* from pieces a join skills b on a.actorId = b.actorId join attrs c on b.actorId = c.actorId ';
    var dbclient = pomelo.app.get('dbclient');
    dbclient.query(sql,function(err,res){
        if(err){
            console.log('actorDao getAllValueInfo fail====>');
            console.log(err);
        }else{
            var actorData = [];
            var pieceData = [];
            var skillData = [];
            var attrData =  [];
            for(var i in res){
                //解析pieces的值
                var data1 = [{value:res[i].p1value1,price :res[i].p1price1},{value:res[i].p1value2,price :res[i].p1price2},{value:res[i].p1value3,price :res[i].p1price3} ,{value:res[i].p1value4,price:res[i].p1price4},
                    {value:res[i].p1value5,price :res[i].p1price5}];
                var data2 = [{value:res[i].p2value1,price :res[i].p2price1},{value:res[i].p2value2,price :res[i].p2price2},{value:res[i].p2value3,price :res[i].p2price3} ,{value:res[i].p2value4,price:res[i].p2price4},
                    {value:res[i].p2value5,price :res[i].p2price5}];
                var data3 = [{value:res[i].p3value1,price :res[i].p3price1},{value:res[i].p3value2,price :res[i].p3price2},{value:res[i].p3value3,price :res[i].p3price3} ,{value:res[i].p3value4,price:res[i].p3price4},
                    {value:res[i].p3value5,price :res[i].p3price5}];
                var data4 = [{value:res[i].p4value1,price :res[i].p4price1},{value:res[i].p4value2,price :res[i].p4price2},{value:res[i].p4value3,price :res[i].p4price3} ,{value:res[i].p4value4,price:res[i].p4price4},
                    {value:res[i].p4value5,price :res[i].p4price5}];
                var jsonData1 = {levels : JSON.parse(JSON.stringify(data1))};
                var jsonData2 = {levels : JSON.parse(JSON.stringify(data2))};
                var jsonData3 = {levels : JSON.parse(JSON.stringify(data3))};
                var jsonData4 = {levels : JSON.parse(JSON.stringify(data4))};
                pieceData.push(jsonData1);
                pieceData.push(jsonData2);
                pieceData.push(jsonData3);
                pieceData.push(jsonData4);

                //解析skills值
                var data5 = [{value:res[i].s1value1,price :res[i].s1price1,mana:res[i].mp1},{value:res[i].s1value2,price :res[i].s1price2,mana:res[i].mp2},{value:res[i].s1value3,price :res[i].s1price3,mana:res[i].mp3} ,{value:res[i].s1value4,price:res[i].s1price4,mana:res[i].mp4},
                    {value:res[i].s1value5,price :res[i].s1price5,mana:res[i].mp5}];
                var data6 = [{value:res[i].s2value1,price :res[i].s2price1,mana:res[i].mp1},{value:res[i].s2value2,price :res[i].s2price2,mana:res[i].mp2},{value:res[i].s2value3,price :res[i].s2price3,mana:res[i].mp3} ,{value:res[i].s2value4,price:res[i].s2price4,mana:res[i].mp4},
                    {value:res[i].s2value5,price :res[i].s2price5,mana:res[i].mp5}];
                var data7 = [{value:res[i].s3value1,price :res[i].s3price1,mana:res[i].mp1},{value:res[i].s3value2,price :res[i].s3price2,mana:res[i].mp2},{value:res[i].s3value3,price :res[i].s3price3,mana:res[i].mp3} ,{value:res[i].s3value4,price:res[i].s3price4,mana:res[i].mp4},
                    {value:res[i].s3value5,price :res[i].s3price5,mana:res[i].mp5}];
                var jsonData5 = {levels : JSON.parse(JSON.stringify(data5))};
                var jsonData6 = {levels : JSON.parse(JSON.stringify(data6))};
                var jsonData7 = {levels : JSON.parse(JSON.stringify(data7))};
                skillData.push(jsonData5);
                skillData.push(jsonData6);
                skillData.push(jsonData7);

                //解析attrs的值
                var data8 = [{value:res[i].a1value1,price :res[i].a1price1},{value:res[i].a1value2,price :res[i].a1price2},{value:res[i].a1value3,price :res[i].a1price3} ,{value:res[i].a1value4,price:res[i].a1price4},
                    {value:res[i].a1value5,price :res[i].a1price5}];
                var data9 = [{value:res[i].a2value1,price :res[i].a2price1},{value:res[i].a2value2,price :res[i].a2price2},{value:res[i].a2value3,price :res[i].a2price3} ,{value:res[i].a2value4,price:res[i].a2price4},
                    {value:res[i].a2value5,price :res[i].a2price5}];
                var data10 = [{value:res[i].a3value1,price :res[i].a3price1},{value:res[i].a3value2,price :res[i].a3price2},{value:res[i].a3value3,price :res[i].a3price3} ,{value:res[i].a3value4,price:res[i].a3price4},
                    {value:res[i].a3value5,price :res[i].a3price5}];
                var jsonData8 = {levels : JSON.parse(JSON.stringify(data8))};
                var jsonData9 = {levels : JSON.parse(JSON.stringify(data9))};
                var jsonData10 ={levels : JSON.parse(JSON.stringify(data10))};
                attrData.push(jsonData8);
                attrData.push(jsonData9);
                attrData.push(jsonData10);

                var  jsonActor = {pieces : JSON.parse(JSON.stringify(pieceData)),skills : JSON.parse(JSON.stringify(skillData)),attrs : JSON.parse(JSON.stringify(attrData))};
                actorData.push(jsonActor);
            }
            utils.invokeCallback(cb,null,JSON.parse(JSON.stringify(actorData)));
        }
    });
};

